package com.copa.gameStore.controller;

import com.copa.gameStore.application.CartApplicationService;
import com.copa.gameStore.dto.CartDto;
import com.copa.gameStore.dto.ValidateCartDto;
import com.copa.gameStore.vo.CartVo;
import com.copa.gameStore.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author copa
 * @createDate 2022-09-27 11:26
 * @function
 */
@RestController
@Api(tags = "购物车服务")
public class CartController {

    @Resource
    private CartApplicationService cartApplicationService;

    @ApiOperation("添加/修改购物车")
    @PostMapping("add")
    public ResponseVo<String> post(@RequestBody @Validated CartDto cartDto) {
        return cartApplicationService.post(cartDto);
    }

    @ApiOperation("获取购物车信息")
    @GetMapping("get")
    public ResponseVo<CartVo> get() {
        return cartApplicationService.get();
    }

    @ApiOperation("删除购物车信息")
    @DeleteMapping("delete")
    public ResponseVo<String> delete(@RequestBody List<Long> ids) {
        return cartApplicationService.delete(ids);
    }

    @ApiOperation("此方法为feign调用，验证购物车信息")
    @PostMapping("validateUser")
    public void validateUser(@RequestBody ValidateCartDto validateCartDto) {
        cartApplicationService.validateUser(validateCartDto);
    }

    @ApiOperation("此方法为feign调用，创建订单后删除购物车信息")
    @PostMapping("deleteByOrder")
    public void deleteByOrder(@RequestBody ValidateCartDto validateCartDto) {
        cartApplicationService.deleteByOrder(validateCartDto);
    }

    @ApiOperation("此方法为feign调用，获取购物车信息")
    @GetMapping("getByUserId")
    public ResponseVo<CartVo> getByUserId(@RequestParam("userId") Long userId) {
        return cartApplicationService.getByUserId(userId);
    }
}
